package com.lvbaoins.creditapp.task;

import com.lvbaoins.creditapp.core.MailCompent;
import com.lvbaoins.creditapp.core.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author : gjb
 * @description:
 * @date : 2020-12-23 10:55
 * @version: : v1.0
 */
public class MailTask {

    private static Logger logger = LoggerFactory.getLogger(MailTask.class);
    private static MailCompent mailCompent = SpringContextUtil.getBean(MailCompent.class);

    public static Runnable sendPolicyTask(String[] to, String name, String mobile) {
        return new Runnable() {
            @Override
            public void run() {
                try {

                    StringBuilder htmlStr = new StringBuilder();
                    htmlStr.append("<table>");
                    htmlStr.append("<tr><td>姓名：</td><td>" + name + "</td></tr>");
                    htmlStr.append("<tr><td>手机号：</td><td>"+ mobile +"</td></tr>");
                    htmlStr.append("</table>");
                    mailCompent.sendHtmlMail(to, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))+ "申请成为渠道", htmlStr.toString());
                } catch (Exception e) {
                    logger.error("[发送邮件]-失败,发送浙商保单回传邮件失败:", e);
                }
            }
        };
    }

}
